using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.Persistent.Base;
using TransLogger.Module.BusinessObjects;

namespace TransLogger.Module.Controllers
{
    public partial class InitializeNewObjectViewController : ViewController
    {
        private NewObjectViewController _detailViewController;
        private OperationHistory _operationHistory;

        public InitializeNewObjectViewController()
        {
            InitializeComponent();
            RegisterActions(components);

            ViewControlsCreated += OnViewControlsCreated;
            Debug.WriteLine("new controller");
        }

        private void OnViewControlsCreated(object sender, EventArgs eventArgs)
        {

        }

        protected override void OnActivated()
        {
            base.OnActivated();
            _detailViewController = Frame.GetController<NewObjectViewController>();
            _detailViewController.NewObjectAction.Executing += NewObjectActionOnExecuting;
            Frame.ViewChanged += FrameOnViewChanged;
            Frame.ViewChanging += FrameOnViewChanging;
        }

        private void FrameOnViewChanging(object sender, ViewChangingEventArgs viewChangingEventArgs)
        {
            if (View.CurrentObject!= null 
                && View.CurrentObject.GetType() == typeof(BusinessObjects.OperationHistory)
                && View.Id == "OperationHistory_ListView_NewRecordOnly")
            {
                _operationHistory = (BusinessObjects.OperationHistory)View.CurrentObject;
                Debug.WriteLine("ser current object");
            }
            
        }

        private void FrameOnViewChanged(object sender, ViewChangedEventArgs viewChangedEventArgs)
        {
            if (_operationHistory != null && View.CurrentObject != null && View.CurrentObject.GetType() == typeof(BusinessObjects.Vehicle))
            {
                var vehicle = (Vehicle)View.CurrentObject;
                Debug.WriteLine("init vehicle lpr");
            }

            Debug.WriteLine(View);
        }

        private void NewObjectActionOnExecuting(object sender, CancelEventArgs cancelEventArgs)
        {

        }
    }
}
